#include "comm.hpp"

using namespace std;

int main()
{
    key_t key = GetKey();
    int shmid = GetShm(key);
    char *s = (char *)shmat(shmid, nullptr, 0);
    cout << "attach shm done" << endl;

    int fd = open(FileName.c_str(), O_WRONLY);
    if(fd < 0)
    {
        cerr << "errno: " << errno << ", strerrno: " << strerror(errno) << endl;
        return false;
    }

    char c = 'a';
    for(; c <= 'z'; c++)
    {
        s[c-'a'] = c;
        cout << "write: " << c << " done" << endl;
        sleep(1);

        int code = 1;
        write(fd, &code, sizeof(code));
    }

    shmdt(s);
    cout << "detach shm done" << endl;
    return 0;
}